package com.seven.good.dao;

import com.seven.good.pojo.BidRecord;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;


public interface BidRecordMapper {
    int deleteByPrimaryKey(Integer brid);

    int insert(BidRecord record);

    int insertSelective(BidRecord record);

    BidRecord selectByPrimaryKey(Integer brid);

    int updateByPrimaryKeySelective(BidRecord record);

    int updateByPrimaryKey(BidRecord record);

    //根据商品id查询出价次数
    @Select("select count(*) from bid_record where gid = #{gid} and flag = 0")
    int selectBuyRecordByGid(Integer gid);
    //倒序查询出价记录价格
    List<BidRecord> selectBidRecoredsByGid(Integer gid);

    //倒序查询出价记录价格（分页）
    List<BidRecord> selectBidRecoredsByGid(@Param("currentPage")Integer currnetPage,@Param("pageSize") Integer pageSize, @Param("gid") Integer gid);
    //根据商品id，出价时间，出价状态
    @Select("select brid from bid_record where bid_state = '领先' and gid = #{gid} and bid_time < #{currentTime} and flag = 0")
    int selectOutBrid(Integer gid, Date currentTime);
    //更改出局记录的状态
    int updateBidStateOutByBrid(Integer brid);


    List<BidRecord> listRecordListById(Integer gid);

    @Select("SELECT COUNT(*) FROM bid_record")
    int countRecords();

    /**
     * @Description：获取某商品的最新竞拍记录
     * @Author: ytj
     * @param: gid 商品编号
     * @return BidRecord 商品记录
     * @CreateDate:  19/10/27
     */
    BidRecord getLatestRecord(Integer gid);

    /**
     * @Description：获取当前商品所有竞价记录
     * @Author: ytj
     * @param: gid 商品编号
     * @CreateDate:  19/11/02
     */
    List<BidRecord> listAllRecordByGid(Integer gid);

    /**
     * @Description：更新商品状态
     * @Author: ytj
     * @param: gid 商品编号； code 商品状态
     * @CreateDate:  19/10/27
     */
    @Update("update good set good_state = #{code} where gid = #{gid}")
    void updateGoodState(Integer gid,Integer code);
}